<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">

<head>
    <th:block th:include="include :: header('模板列表')" />
    <th:block th:include="include :: select2-css" />
</head>

<body class="gray-bg">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                             <p>  模板名：</p> 
                                <input type="text" class="form-control" name="templateName" />
                            </li>
                            <li>
                            <P>是否内置：</P>    
                                <select name="built" class="form-control" th:with="type=${@dictTag.getType('sys_yes_no')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue=='Y'?1:0}"></option>
                                </select>
                            </li>
                            <li>
                             <P>状态：</P>   
                                <select name="visible" class="form-control" th:with="type=${@dictTag.getType('oly_template_visible')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                               <P>模板类型：</P> 
                                <select name="templateType" class="form-control" th:with="type=${@dictTag.getType('oly_template_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.treeTable.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab(0)" shiro:hasPermission="oly:template:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-tree-table" data-mobile-responsive="true"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: select2-js" />
    <script th:inline="javascript">
        var prefix = ctx + "oly/template";
        var editFlag = [[${@permission.hasPermi('oly:template:edit') }]];
        var addFlag = [[${@permission.hasPermi('oly:template:add') }]];
        var removeFlag = [[${@permission.hasPermi('oly:template:remove') }]];
        var viewFlag = [[${@permission.hasPermi('oly:template:example') }]];
        var bu = [[${@dictTag.getType('sys_yes_no') }]];
        var vi = [[${@dictTag.getType('oly_template_visible') }]];
        var ty = [[${@dictTag.getType('oly_template_type') }]];
        function viewTemplate(id) {
            $.modal.openTab('模板展示', prefix + "/example/" + id);

        }
        $(function () {
            var options = {
                code: "templateId",
                parentCode: 'parentId',
                uniqueId: "templateId",
                expandAll: false,
                expandFirst: false,
                url: prefix + "/list",
                createUrl: prefix + "/add/{id}",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove/{id}",
                modalName: "数据模板",
                columns: [{
                    field: 'selectItem',
                    radio: true
                },
                {
                    field: 'templateId',
                    title: '模板id'
                },
                {
                    field: 'templateName',
                    title: '模板名'
                },
                {
                    field: 'templateType',
                    title: '模板类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(ty, value);
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    field: 'built',
                    title: '是否内置',
                    formatter: function (value, row, index) {

                        if (value == 1) {
                            value = "Y";
                        }
                        else {
                            value = "N";
                        }
                        return $.table.selectDictLabel(bu, value);
                    }
                },
                {
					field: 'createTime',
					title: '创建时间'
				},
                {
                    field: 'visible',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(vi, value);
                    }
                },
                {
                    title: '操作',
                    align: 'left',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.templateId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.templateId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        if (row.templateType == 0) {
                            actions.push('<a class="btn btn-success btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.addTab(\'' + row.templateId + '\')"><i class="fa fa-plus"></i>添加下级</a>');
                        }
                        if (row.templateType == 2) {
                            actions.push('<a class="btn btn-success btn-xs ' + viewFlag + '" href="javascript:void(0)" onclick="viewTemplate(\'' + row.templateId + '\')"><i class="fa fa-eye"></i>模板演示</a>');
                        }
                        return actions.join('');
                    }
                }]
            };
            $.treeTable.init(options);

        })
    </script>
</body>

</html>